//
//  RW_MineView.m
//  SleepApp
//
//  Created by MAC on 2021/3/22.
//  Copyright © 2021 RiceWang. All rights reserved.
//

#import "RW_MineView.h"
#import "RW_ItemCollectionViewCell.h"
#import "RW_HeaderCollectionViewCell.h"
#import "RW_LoginViewController.h"
#import "RW_FeedbackViewController.h"
#import "RW_FuncViewController.h"

@interface RW_MineView()
@property (nonatomic,strong) WLCollectionView *wlclass_collection_view;

@end
@implementation RW_MineView

- (instancetype)init
{
    self = [super init];
    if (self) {
        self.backgroundColor = HexColor(@"f6f6f6");
        [self addSubview:self.wlclass_collection_view];
        [self.wlclass_collection_view mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.insets(UIEdgeInsetsZero);
        }];
    }
    return self;
}
-(void)setWlclass_view_model:(RW_MineViewModel *)wlclass_view_model{
    _wlclass_view_model = wlclass_view_model;
   
    [_wlclass_view_model getItemViewSuccess:^(NSArray<WLBaseCollectionViewLayerSection *> * _Nonnull response) {
        [self.wlclass_collection_view setSectionList:response];
    } fail:nil];
    [self reloadUserInfo];
}
/** 刷新用户信息 */
-(void)reloadUserInfo{
    [_wlclass_view_model getUserHeaderViewSuccess:^(NSArray<WLBaseCollectionViewLayerSection *> * _Nonnull response) {
        [self.wlclass_collection_view setSectionList:response];
    } fail:nil];
}

#pragma mark -- WLCollectionView 代理
- (void)wl_collectionView:(UICollectionView *)collectionView
               layerModel:(WLBaseCollectionViewLayerModel *)layerModel
             layerRowData:(id)rowData
             didIndexPath:(NSIndexPath *)indexPath{
    if ([rowData isKindOfClass:RW_ItemCollectionViewCellModel.class]){
        RW_ItemCollectionViewCellModel *model = rowData;
        if (model.item_type == Mine_Item_Type_Feedback){//意见反馈
            [RW_FeedbackViewController pushFeedbackFromVc:[self viewController_wl]];
        } else if (model.item_type == Mine_Item_Type_Purchase){//内购商品列表
            
        } else if (model.item_type == Mine_Item_Type_Statement){//内容声明
            
        } else if (model.item_type == Mine_Item_Type_PlayerClass){//内容声明
            [RW_FuncViewController pushFuncFromVc:[self viewController_wl]];
        }
    } else if ([rowData isKindOfClass:RW_HeaderCollectionViewCellModel.class]){
        RW_HeaderCollectionViewCellModel *model = rowData;
        if (!model.user_model){
            [RW_LoginViewController pushLoginFromVc:[self viewController_wl]];
        }
    }
}

#pragma mark -- 懒加载
-(WLCollectionView *)wlclass_collection_view{
    if (!_wlclass_collection_view){
        _wlclass_collection_view = [WLCollectionView initWithVerticalDelegate:self];
    }
    return _wlclass_collection_view;
}

@end
